<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="org.lsms.dao.impl.*" %>
<%@ page import="org.lsms.bean.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>Member Paper Assign Detail Page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="LSMS,ICSEE,MEMBER">
	
	<link rel="stylesheet" type="text/css" href="../css/author_layout.css">
	<link rel="stylesheet" type="text/css" href="../css/hyper_link_style.css">
	
	<style type="text/css">
	
		th{
			width:100px;
		}
		td{
			text-align:center;
		}
	
	</style>
	
	<script type="text/javascript">
	
	function openpage(curpage)
	{
		document.spage.page.value = curpage ;		
		document.spage.submit() ;
	}
	
	function a_openpage(a_curpage)
	{
		document.a_spage.a_page.value = a_curpage ;		
		document.a_spage.submit() ;
	}
	
	function check(paper_id,reviewer_id)
	{
		var a = window.confirm("Are you sure you want to assign paper "+paper_id+" to reviewer "+reviewer_id+"?");
		if(a){
			return true;
		}else{
			return false;
		}
	}
	
	function check_all(paper_id,member_id)
	{
		var s = "";
		var i = 0;
		var length = document.assign_paper.assignment.length;
		for(i=0;i<length;i++)
		{
			if(document.assign_paper.assignment[i].checked)
			{
				s = s+document.assign_paper.assignment[i].value+",";
			}
		}
		
		if(s!=""){
			var a = window.confirm("Are you sure you want to assign paper "+paper_id+" to reivewer "+s+"?" )
			if(a){
				window.location = "../paper_assign2_all?paper_id="+paper_id+"&reviewer_id="+s+"&member_id="+member_id;
				
			}else{
				return false;
			}
		}
		else{
			alert("Please select at least one paper!");
			return false;
		}
	}
	
	function selectall()
	{
    	
    	var b = document.getElementsByName("select_all");
   		if(b[0].checked==true){
   		var ass = document.getElementsByName("assignment");
   		for (var i=0; i<ass.length; i++)
      		ass[i].checked = true;
   		}
   		else
   		{
   		var ass = document.getElementsByName("assignment");
  		 for (var i=0; i<ass.length; i++)
      		ass[i].checked = false;
   		}
	}
	
	</script>
	
	
  </head>
  
  <body>
  	<%
  		int paper_id = Integer.parseInt(request.getParameter("paper_id"));
  	 	int member_id = Integer.parseInt(session.getAttribute("userid").toString());
  	 %>
	<div id="container">
		<div id="header" class="logo_image"></div>
		<div class="nav"></div>
		<div id="author_menu" class="border">
			<table border="0" width="100%"  >
				<tr>
					<td  bgcolor="#CCCCCC"><a href="../index.jsp">Home</a></td>
				</tr>
				<tr>
					<td  bgcolor="#CCCCCC"><a href="select_topic.jsp">Select Topics</a></td>
				</tr>
				<tr>
				<%
					DaoImpl impl = new DaoImpl();
					HashMap<String,Integer> hm = impl.get_site_setting();
					int reviewer_invite = hm.get("reviewer_invite");
					if(reviewer_invite==1){
				 %>
					<td  bgcolor="#CCCCCC"><a href="invite_reviewer.jsp">Invite Reviewer</a></td>
				<%
					}else{
				 %>
				 	<td  bgcolor="#CCCCCC"><a href="../error/invite_reviewer_forbidden.jsp">Invite Reviewer</a></td>	
				<%
					}
				 %>	
				</tr>
				<tr>
					<td  bgcolor="#CCCCCC"><a href="reviewer_conf.jsp">Reviewer Confirmation</a></td>
				</tr>
				<tr>
					<td  bgcolor="#CCCCCC"><a href="paper_assign.jsp">Paper Status/Paper Assign</a></td>
				</tr>
				<tr>
					<td  bgcolor="#CCCCCC"><a href="member_decision.jsp">Decision</a></td>
				</tr>
				<tr>
					<td  bgcolor="#CCCCCC"><a href="modify_info.jsp">Modify Information</a></td>
				</tr>
				<tr>
					<td  bgcolor="#CCCCCC"><a href="../logout">Log Out</a></td>
				</tr>
			</table>
		</div>
		
		<div id="content" class="bg_color border">
		
			<p><b>Paper Assign</b></p>
			<div style="margin:15px">
				<div id="paper_info">
				<p align="left"><b>Paper Information</b></p> 
				<table align="center" border="0" style="width:650px">
				<%
					Paper paper = new Paper();
					paper = impl.get_paper_info(paper_id);
				 %>
				<tr>
					<th>Paper ID</th>
					<td style="text-align:left">
					<%
						out.print(paper_id);
					 %>
					</td>
				</tr>
				<tr>
					<th>Title</th>
					<td style="text-align:left">
					<%
						out.print(paper.getPapertitle());
					 %>
					</td>
				</tr>
				<tr>
					<th>Abstract</th>
					<td style="text-align:left">
					<%
						out.print(paper.getPaperabstract());
					 %>
					</td>
				</tr>
				<tr>
					<th>Key Words</th>
					<td style="text-align:left">
					<%
						out.print(paper.getPaperkeywords());
					 %>
					</td>
				</tr>
				<tr>
					<th>Topic 1</th>
					<td style="text-align:left">
					<%
						String topic1_name = paper.getFirsttopic();
						String topic1_content = impl.get_topic_content(topic1_name);
						out.print(topic1_content);
					 %>
					</td>
				</tr>
				<tr>
					<th>Topic 2</th>
					<td style="text-align:left">
					<%
						String topic2_name = paper.getSecondtopic();
						String topic2_content = impl.get_topic_content(topic2_name);
						out.print(topic2_content);
					 %>
					</td>
				</tr>
				<tr>
					<th>Author(s)</th>
					<td style="text-align:left">
					<%
						out.print(paper.getAuthorname());
					 %>
					</td>
				</tr>
				<tr>
					<td colspan="2" style="text-align:center">
					<%
						String savename = "..";
						savename += paper.getSavename();
					 %>
					 <a href="<%=savename %>">DownLoad</a>
					</td>
				</tr>
				</table>
				</div>
				
				<p align="left"><b>Assigned Reviewers</b></p>
				<div id="assigned_reviewer" class="border">
				
				<table align="center" border="0" style="width:650px">
				<tr>
					<th>ID</th>
					<th>Login Name</th>
					<th>Email</th>
					<th>Topics</th>
					<th>Status</th>
					<th>&nbsp;</th>
				</tr>
				<%
					int page_count = 1;
					int row = 2;
					int sum_page = 1;
					int sum_row = impl.get_reviewer_num_of_one_paper(paper_id,member_id);
					
					try{
						page_count = Integer.parseInt(request.getParameter("page"));
						sum_row = Integer.parseInt(request.getParameter("sum_row"));
						System.out.println(page_count+" "+sum_row);
						}catch(Exception e){}
					
					HashMap<String,List<User>> map = impl.get_paper_assign2(paper_id,member_id,page_count,row);
					List<User> list = map.get("all");
					Iterator it = list.iterator();
					if(list.size()<1){
					
				 %>
				 <tr>
				 	<td colspan="5">
				 	<p align="center">No Assign Information!</p>
				 	</td>
				 </tr>
				 <%
				 	}
				 	for(int i=0;i<list.size();i++){
				 		User user = list.get(i);
				  %>
				  <tr>
				  	<td>
				  	<%
				  		out.print(user.getUserid());
				  	 %>
				  	</td>
				  	<td>
				  	<%
				  		out.print(user.getLoginname());
				  	 %>
				  	</td>
				  	<td>
				  	<%
				  		out.print(user.getEmail());
				  	 %>
				  	</td>
				  	<td>
				  	<%
				  		String topics = impl.user_select_topics_info(user.getLoginname());
				  		out.print(topics); 
				  	 %>
				  	</td>
				  	<td>
				  	<%
				  		int status = impl.get_paper_assign2_status(paper_id,member_id,user.getUserid());
				  	 	if(status==0){
				  	 		out.print("<font color='red' size='2'><b>NOT CHECKED!</b></font>");
				  	 	}else{
				  	 		out.print("<font color='green' size='2'><b>CHECKED!</b></font>");
				  	 	}
				  	 %>
				  	</td>
				  	<td>
				  	<%
				  		if(status==1){
				  			out.print(' ');
				  		}else{	
				  	 %>
				  	 <a href="../send_email_to_urge?user_id=<%=user.getUserid()%>">Urge</a>
				  	</td>
				  	<%
				  		}
				  	 %>
				  </tr>
				  <%
				  	}
				  %>
				</table>
				
				</div>	
				
				<form action="paper_assign2_detail.jsp?paper_id=<%=paper_id%>" method="post" name="spage">
				<table width="95%" border="0" align="center">
				<tr>
					<td>
					&nbsp;
					</td>
					<td>
					<%
						sum_page = (sum_row + row -1) / row;
						if(list.size()>=1){
					%>
				 	<div align="center">
				 	<input type="button" value="First" onClick="openpage(1)"
				  	<%=page_count==1 ? "disabled" : "" %>>
				 
				 	<input type="button" value="Preivew" onClick="openpage(<%=page_count-1%>)"
				  	<%=page_count==1? "disabled" : "" %>>
				 
				 	<input type="button" value="Next" onClick="openpage(<%=page_count+1%>)"
				  	<%=page_count==sum_page? "disabled" : "" %>>
				 
				 	<input type="button" value="Last" onClick="openpage(<%=sum_page%>)"
				  	<%=page_count==sum_page? "disabled" : "" %>>
				 
				 	<input type="hidden" name="page" value="">&nbsp;
				 
				 	<font color="red" size="3"><%=page_count%></font> /
				 	<font color="red" size="3"><%=sum_page%></font>
				 
				 	</div>
				 	<%
				 	}
				  	%>
					</td>
				</tr>
				</table>
				</form>	
				
				<p align="left"><b>Assign To New Reviewers</b></p>	
				<div id="assign_to_new_reviewer" class="border">
					<form name="assign_paper" onsubmit="show()">
					<table align="center" border="0" style="width:650px;text-align:center">
					<tr>
						<th>&nbsp;</th>
						<th>ID</th>
						<th>Login Name</th>
						<th>Email</th>
						<th>Topic(s)</th>
						<th>Assigned Papers</th>
						<th>&nbsp;</th>
					</tr>
					<%
						int a_page_count = 1;
						int a_row = 3;
						int a_sum_page = 1;
						int a_sum_row = impl.get_unassign2_num(paper_id);
						try{
							a_page_count = Integer.parseInt(request.getParameter("a_page"));
							a_sum_row = Integer.parseInt(request.getParameter("a_sum_row"));
							System.out.println(a_page_count+","+a_sum_row);
						}catch(Exception e){};
						HashMap<String,List<User>> a_map = impl.get_reviewer_unassign2(paper_id,a_page_count,a_row);
						List<User> a_list = new ArrayList<User>();
						a_list = a_map.get("all");
						Iterator a_it = a_list.iterator();
						if(a_list.size()<1){
					%>
			 		<tr>
			 			<td colspan="6">
			 			<p align="center">No Reviewer To Assign!</p>
			 			</td>
			 		</tr>
			 		<%
			 		}
			 			for(int j=0;j<a_list.size();j++){
			 				User a_user = a_list.get(j);
			  		%>
			  		<tr>
			  			<td>
			  			<input type="checkbox" name="assignment" value=<%=a_user.getUserid()%>>
			  			</td>
			  			<td>
			  			<%
			  				out.print(a_user.getUserid());
			  	 		%>	
			  			</td>
			  			<td>
			  			<%
			  				out.print(a_user.getLoginname());
			  	 		%>
			  			</td>
			  			<td>
			  			<%
			  				out.print(a_user.getEmail());
			  	 		%>
			  			</td>
			  			<td>
			  			<%
			  				String a_loginname = a_user.getLoginname();
			  				String a_topics = impl.user_select_topics_info(a_loginname);
			 				out.print(a_topics);
			  	 		%>
			  			</td>
			  			<td>
			  			<%
			  				int num = impl.get_reviewer_assign_num(a_user.getUserid());
			  				out.print(num);
			  			 %>
			  			</td>
			  			<td>
			  			<a href="../paper_assign2?reviewer_id=<%=a_user.getUserid()%>&paper_id=<%=paper_id %>&member_id=<%=member_id %>" onclick="return check(<%=paper_id %>,<%=a_user.getUserid()%>)">Assign</a>
			  			</td>
			  		</tr>
			  		<%
			  		}
			   		%>	
			   		<tr>
			   				<td colspan="6">
			   				<hr>
			   				</td>
			   		</tr>
			  		<tr>
			  			<td>
			  			<input type="checkbox" name="select_all" value="All" onclick="selectall()">All
			  			</td>	
			  			<td colspan="4">
			  			&nbsp;
			  			</td>	
			  			<td>
			  			<input type="button" value="Assign" onclick="check_all(<%=paper_id %>,<%=member_id %>)">
			  			</td>
			  		</tr>
			   		</table>
			   		</form>
				</div>	
				<form action="paper_assign2_detail.jsp?paper_id=<%=paper_id%>" method="post" name="a_spage">
				<table width="95%" border="0" align="center">
				<tr>
					<td>
					&nbsp;
					</td>
					<td>
					<%
						a_sum_page = (a_sum_row + a_row -1) / a_row;
						if(a_list.size()>=1){
				 	%>
				 	<div align="center">
					<input type="button" value="First" onClick="a_openpage(1)"
				  	<%=a_page_count==1 ? "disabled" : "" %>>
				 
				 	<input type="button" value="Preivew" onClick="a_openpage(<%=a_page_count-1%>)"
				  	<%=a_page_count==1? "disabled" : "" %>>
				 
				 	<input type="button" value="Next" onClick="a_openpage(<%=a_page_count+1%>)"
				  	<%=a_page_count==a_sum_page? "disabled" : "" %>>
				 
				 	<input type="button" value="Last" onClick="a_openpage(<%=a_sum_page%>)"
				  	<%=a_page_count==a_sum_page? "disabled" : "" %>>
				 
				 	<input type="hidden" name="a_page" value="">&nbsp;
				 
				 	<font color="red" size="3"><%=a_page_count%></font> /
				 	<font color="red" size="3"><%=a_sum_page%></font>
				 
				 	</div>
				 	<%
				 	}
				  	%>
					</td>
				</tr>
				</table>
				</form>	
			</div>	
		</div>
		
		<div class="nav"></div>
			
		<div id="footer" class="footer_color border">
			<p align="center"><b>&copy;2010 LSMS-All Rights Reserved.</b></p>
			<p align="center"> <b>Powered by Shu.</b></p>
		</div>
	</div>
  </body>
</html>
